<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*
        async函数的返回值:
         -async函数默认返回pending状态的promise实例
          -当await等待的promise对象变成失败状态时,async函数的返回值与这个失败的实例保持一致,同时中止后面代码的执行
         -当async函数内部的代码全部执行完成后,返回成功peommise实例,值为async函数return的值
         -当async内部return的是promise实例时,async函数的值与这个promise保持一致
         -当async函数内部有错误,则直接中止代码运行,返回失败的promise实例,值为错误信息
        


        */
        async function getData(){
            // console.log("asyncResult",asyncResult)
            console.log("start");
            const awaitResult = await new Promise((resolve,reject)=>{
                try{
                    setTimeout(()=>{
                        console.log("timer");
                        // resolve("data")
                        reject("err")
                    },2000)
                }catch(e){
                    reject(e.message)
                }
            })

            console.log("awaitResult",awaitResult);

            console.log("计时器后的语句");

            // return 1
            return new Promise((resolve,reject)=>{
                // resolve(1)
                reject("出错啦")
            })
        }

        const result = getData()
        console.log("result",result);
    </script>
</body>
</html>